import { SingletonFactory } from "./framework/utils/SingletonFactory";
import ViewModelBase from "./framework/view/ViewModelBase";
import ModelDebug from "./game/mvc/debug/model/ModelDebug";
import ModelMainDemo from "./game/mvc/demo_main/model/ModelMainDemo";
import ModelFlyIcon from "./game/mvc/fly_icon/model/ModelFlyIcon";
import ModelGuide from "./game/mvc/guide/model/ModelGuide";
import ModelPlayer from "./game/mvc/player/model/ModelPlayer";

class GameDataCenter {    
    private _modelMap:{[key:string]:ViewModelBase} = {}

    private _loadModel<T extends ViewModelBase>(c: { new(): T }): T {
        let obj = SingletonFactory.getInstance(c);
        this._modelMap[c["modelName"]] = obj;
        return obj;
    }

    clear() {
        for (const key in this._modelMap) {
            const model = this._modelMap[key];
            model.clear();
        }
    }
    /**
     * 加载游戏的model,所有需要在游戏启动的时候就需要初始化的model以及提供对外接口的model都需要在此处进行加载
     */
    initModels() {
        this._loadModel(ModelPlayer);
        this._loadModel(ModelMainDemo);
        this._loadModel(ModelGuide);
        this._loadModel(ModelDebug);
        this._loadModel(ModelFlyIcon);
    }

    /**
     * 通过名字获取model
     * @param name model的名字
     */
    getModelByName(name:string) {
        return this._modelMap[name];
    }
}

export default new GameDataCenter();